﻿using ProjectDanmaku.Data;
using ProjectDanmaku.Entity;
using UnityEditor;
using UnityEngine;

namespace Editor.ProjectDanmaku.Inspector
{
    public class EntityLayerBitInspector : UnityEditor.Editor
    {
        [SerializeField] private EntityLayerBitSettings settingsAsset;
        
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            var prop = serializedObject.FindProperty("layerBit");
            var idx = prop.intValue - 1;

            if (idx < 0 || idx >= settingsAsset.layerBitNames.Count)
                idx = -1;
            
            var newIdx = EditorGUILayout.Popup(
                "Layer Bits", idx, settingsAsset.layerBitNames.ToArray());
            
            prop.intValue = newIdx + 1;

            serializedObject.ApplyModifiedProperties();

            DrawDefaultInspector();
        }
    }
}